package com.ushine.web.component.design.chain.salary.factory;

import com.ushine.web.component.design.chain.config.ApplicationContextHelper;
import com.ushine.web.component.design.chain.config.ChainBaseParams;
import com.ushine.web.component.design.chain.factory.AbstractChainTemplateFactory;
import com.ushine.web.component.design.chain.handler.AbstractChainTemplateHandler;
import com.ushine.web.component.design.chain.salary.handler.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yls
 * @Date: 2022/03/04 09:09
 * @Description: 薪资计算链工厂，可以创建多个不同的计算链
 * @Version 1.0
 */
@Component
public class SalaryCalculateChainFactory extends AbstractChainTemplateFactory {
    @Resource
    public ApplicationContextHelper applicationContextHelper;

    /**
     * 功能描述:
     * 〈采用工厂模式创建过滤链〉
     *
     * @return : java.util.List<com.ushine.web.component.design.chain.handler.ChainTemplateHandler>
     * @author : yls
     * @date : 2022/03/04 11:13
     */
    public List<AbstractChainTemplateHandler<ChainBaseParams>> initSalaryChainTemplateHandler() {
        List<AbstractChainTemplateHandler<ChainBaseParams>> salaryChainHandlers = new ArrayList<>(6);
        /*
         * 基础过滤链：数据准备=》薪资计算的细节计算（可多个）=》上月补发（具体顺序根据业务来） =》汇总薪资计算 =》保存薪资计算结果信息
         */
        creteGatewayHandle(applicationContextHelper, SalaryPrepareHandler.class, 0, salaryChainHandlers);
        creteGatewayHandle(applicationContextHelper, SalaryDetailsHandler.class, 1, salaryChainHandlers);
        creteGatewayHandle(applicationContextHelper, LastMonthSalaryHandler.class, 2, salaryChainHandlers);
        creteGatewayHandle(applicationContextHelper, SummarySalaryHandler.class, 3, salaryChainHandlers);
        creteGatewayHandle(applicationContextHelper, SaveCalculateResultHandler.class, 4, salaryChainHandlers);
        /*
         * 初始化过滤链
         */
        initGatewayHandles(salaryChainHandlers);
        return salaryChainHandlers;
    }
}
